package cn.itsource.org.controller;

import cn.itsource.basic.base.domain.ShopReject;
import cn.itsource.basic.utli.AjaxResult;
import cn.itsource.basic.utli.EmailUtil;
import cn.itsource.basic.utli.PageList;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.query.ShopQuery;
import cn.itsource.org.service.IShopService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private IShopService shopService;
    
    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody Shop shop){
        try {
            System.out.println(shop);
            shopService.settlement(shop);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"系统错误");
        }

    }
    //查询所有
    @GetMapping
    @ApiOperation(value = "查询所有" )
    public List<Shop> queryAll(){
        return shopService.querytAll();
    }

    //基于id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "基于id查询")
    //@PathVariable 获取将地址栏上面的id
    public Shop queryById(@PathVariable("id") Long id){
        return shopService.queryByid(id);
    }

    //分页查询
    @PostMapping
    @ApiOperation(value = "分页查询")
    public PageList<Shop> queryByPage(@RequestBody ShopQuery query){
        return  shopService.queryByPage(query);
    }

    //通过审核
    @PutMapping("/pass")
    public AjaxResult pass(@RequestBody ShopReject reject){
        try {
            shopService.pass(reject);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    //驳回
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody ShopReject reject){
        try {
            shopService.reject(reject);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }
    //驳回注册
    @GetMapping("/rejectShop/{id}")
    public AjaxResult rejectShop(@PathVariable("id") Long id){
        System.out.println(id);
        try {
            Shop shop = shopService.queryByid(id);
            return  AjaxResult.me().setResultObj(shop);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }
    //禁用
    @DeleteMapping("/{id}")
    public AjaxResult disable(@PathVariable("id") Long id){
        try {
            shopService.disable(id);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    //批量删除
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        try {
            shopService.batchDeletedelect(ids);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }
}
